/**
 * 
 */
package com.tien.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
/**
 * @author tien
 *
 */
public abstract class AbstractAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{
	   
    private static final long serialVersionUID = 1L;
   
    private String isMax;

    private String limit;
    private boolean noPaging;
    private PagingBean pagingBean;
    private String portletId;
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    private String start;
   
    protected void doSetPagingBean(int totalRows) throws Exception{
        int iTotalRows = 0;
        try {
            iTotalRows = totalRows;//Integer.parseInt(totalRows);
            } catch(NumberFormatException  ex) {
        }
        int iStart = Integer.parseInt(this.getStart());
        int iRowsPerPage = Integer.parseInt(this.getLimit());
       
        int iTotalPages = iTotalRows%iRowsPerPage == 0?iTotalRows/iRowsPerPage:iTotalRows/iRowsPerPage+ 1;
        int iCurrentPage = iStart/iRowsPerPage + 1;
        if("true".equals(this.getIsMax())){
            setPagingBean(new PagingBean(iTotalRows, iTotalPages, iRowsPerPage, iCurrentPage, 15));
        }else{
            setPagingBean(new PagingBean(iTotalRows, iTotalPages, iRowsPerPage, iCurrentPage, 5));
        }
       
    }

    public String getIsMax() {
        return isMax;
    }

    public String getLimit() {
        return limit;
    }
   
    public PagingBean getPagingBean() {
        return pagingBean;
    }
    public String getPortletId() {
        return portletId;
    }
    public String getStart() {
        return start;
    }
    public boolean isNoPaging() {
        return noPaging;
    }
   
    public void setIsMax(String isMax) {
        this.isMax = isMax;
    }
    public void setLimit(String limit) {
        this.limit = limit;
    }
    public void setNoPaging(boolean noPaging) {
        this.noPaging = noPaging;
    }
    public void setPagingBean(PagingBean pagingBean) {
        this.pagingBean = pagingBean;
    }
    public void setPortletId(String portletId) {
        this.portletId = portletId;
    }
   
    public void setServletRequest(HttpServletRequest req) {
        this.request = req;
    }
   
    public void setServletResponse(HttpServletResponse resp) {
        this.response = resp;
    }
   
   
    public void setStart(String start) {
        this.start = start;
    }
}